package com.monkey.thread;

import java.util.concurrent.TimeUnit;

/**
 * User: zhangqi
 * Date: 2024/8/17
 *
 * @Description:Join和Yiled的区别
 */

public class JoinYieldThread {
    public static void main(String[] args) throws InterruptedException {
        Thread thread1 = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    TimeUnit.SECONDS.sleep(3);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("线程执行完成:" + Thread.currentThread().getName());
            }
        },"one");
        Thread thread2 = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    TimeUnit.SECONDS.sleep(3);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("线程执行完成:" + Thread.currentThread().getName());
            }
        },"two");
        thread1.start();
        thread2.start();
        thread1.join();
        System.out.println("线程执行完成:" + Thread.currentThread().getName());
    }
}
